<?php

namespace app\api\model\goods;

use think\Model;


class GoodsCategory extends Model
{

    

    

    // 表名
    protected $name = 'goods_category';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [

    ];
    
    public function getImageAttr($value, $data)
    {
        return $value ? cdnurl($value, true) : cdnurl('/assets/img/default.png', true);
    }

    protected static function init()
    {
        self::afterInsert(function ($row) {
            if (!$row['weigh']) {
                $pk = $row->getPk();
                $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
            }
        });
    }

    
    public function goodslist(){
        return $this->hasMany('Goods', 'goods_category_id', 'id');
    }






}
